<template>
  <div class="home-container">
    <van-nav-bar fixed>
      <template #left>
        <div class="logo"></div>
      </template>
      <template #right>
        <van-button round class="search-btn" size="small" icon="search"
          >搜索
        </van-button>
      </template>
    </van-nav-bar>
    <van-tabs v-model="active">
      <van-tab v-for="item in 10" :key="item" :title="'标签 ' + item">
        <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
          <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多了"
            @load="onLoad"
          >
            <van-cell v-for="item in list" :key="item" :title="item" />
          </van-list>
        </van-pull-refresh>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
    };
  },
  methods: {
    onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      setTimeout(() => {
        for (let i = 0; i < 10; i++) {
          this.list.push(this.list.length + 1);
        }

        // 加载状态结束
        this.loading = false;

        // 数据全部加载完成
        if (this.list.length >= 40) {
          this.finished = true;
        }
      }, 1000);
    },
  },
};
</script>

<style lang="less">
.home-container {
  height: 100vh;
  padding-top: 46px;
  padding-bottom: 50px;
  box-sizing: border-box;
  /* 1.顶部栏 */
  .van-nav-bar {
    .logo {
      /* 注意点
      如果在图片路径中使用@，默认前面会有./(./@/image.png) 导致编译器报错
      解决： 在@前面添加~ (去掉默认./)
      */
      background: url("~@/assets/logo.png") no-repeat;
      background-size: cover;
      width: 100px;
      height: 30px;
    }

    // 搜索按钮
    .search-btn {
      background-color: #5babfb;
      width: 100px;
      font-size: 14px;
      border: none;
      .van-icon {
        color: #fff;
      }
      .van-button__text {
        color: #fff;
      }
    }
  }
  .van-tabs {
    height: 100%;

    .van-tabs__wrap {
      position: fixed;
    }
    .van-tabs__content {
      padding-top: 46px;

      padding-bottom: 46px;
    }
  }
}
</style>